package websocket

import (
	"github.com/gorilla/websocket"
	"sync"
)

type UserConn struct {
	ConnId string
	UserId string
	Lock   sync.Mutex
	Conn   *websocket.Conn
}

func NewUserConn(userId string, connId string, conn *websocket.Conn) *UserConn {
	return &UserConn{UserId: userId, ConnId: connId, Lock: sync.Mutex{}, Conn: conn}
}

func (u *UserConn) Send(msg []byte) error {
	u.Lock.Lock()
	defer u.Lock.Unlock()
	return u.Conn.WriteMessage(1, msg)
}
